import Router from 'koa-router';
import { readRecordFile } from '../db';
import { Logger, resFail, resSuccess } from '../utils';

const router: Router = new Router();

router.get('/', async (ctx) => {
  const { query } = ctx.request;

  try {
    const doc = await readRecordFile(query.sessionId ? query.sessionId.toString() : '');
    ctx.response.body = resSuccess(doc);
  } catch (error) {
    Logger.error(error);
    ctx.response.body = resFail('查询失败');
  }
});

export default router.routes();
